package com.mmm.order.controller;


import com.mmm.common.vo.Paging;
import com.mmm.common.vo.SuccessVo;
import com.mmm.feign.client.UserClient;
import com.mmm.order.entity.Express;
import com.mmm.order.service.ExpressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * (Express)表控制层
 *
 * @author One
 * @since 2022-03-05 21:09:38
 */
@RestController
@RequestMapping("express")
public class ExpressController {
    /**
     * 服务对象
     */
    @Resource
    private ExpressService expressService;

    @Autowired
    private UserClient userClient;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public SuccessVo<Express> selectOne(@PathVariable("id") Long id) {
        return new SuccessVo<>(this.expressService.findById(id));
    }

    @PutMapping("/put")
    public SuccessVo<Express> insert(HttpServletRequest request, @RequestBody Express express) {
        return new SuccessVo<>(1, expressService.insert(request, express));
    }

    @DeleteMapping("/delete/{id}")
    public SuccessVo<Boolean> delete(@PathVariable Long id) {
        return new SuccessVo<>(2, expressService.deleteById(id));
    }

    @PostMapping("/update")
    public SuccessVo<Express> update(@RequestBody Express express) {
        return new SuccessVo<>(3, expressService.update(express));
    }
    @PostMapping("/addOrder")
    public SuccessVo<Express> addOrder(@RequestHeader("Authorization") String authorization,@RequestBody Express express) {
        return new SuccessVo<>(3, expressService.addOrder(authorization,express));
    }

    @GetMapping("/list")
    public SuccessVo<com.mmm.common.vo.Paging<Express>> page(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        return new SuccessVo<>(expressService.list(page, size));
    }
    @GetMapping("/list/byUniversity")
    public SuccessVo<com.mmm.common.vo.Paging<Express>> byUniversity(@RequestHeader("Authorization") String authorization,@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        return new SuccessVo<>(expressService.byUniversity(authorization,page, size));
    }

    //获取取件地址的订单
    @GetMapping("/byDeliveryId/{id}")
    public SuccessVo<Paging<Express>> byDeliveryId(@PathVariable Integer id, @RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        return new SuccessVo<>(expressService.byDeliveryId(id,page,size));
    }
}